package com.zhilifang.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 读取本地硬盘图片配置
 * 
 * @author yan
 */
@Configuration
public class HDDImgConfig extends WebMvcConfigurerAdapter {
	
	@Value("${upload-path}")
	private String path;

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		if(isLinux()==true){
			path = "/usr/webImg/icare/";
			registry.addResourceHandler("/localImg/**").addResourceLocations("file:"+path);
		}else{
			registry.addResourceHandler("/localImg/**").addResourceLocations("file:"+path);
		}
		super.addResourceHandlers(registry);
	}
	
	
	/** 
	* 判断是linux系统还是其他系统 
	* 如果是Linux系统，返回true，否则返回false 
	*/ 
	public static boolean isLinux() { 
		return System.getProperty("os.name").toLowerCase().indexOf("linux") >= 0; 
	}

}
